//package com.woniuxy.xiangruicommonutilserver.service.impl;
//
//import com.woniuxy.xiangruicommonutilserver.bean.WorkDayInnerBean;
//import com.woniuxy.xiangruicommonutilserver.bean.WorkResultBean;
//import com.woniuxy.xiangruicommonutilserver.dao.WorkInfoDao;
//import com.woniuxy.xiangruicommonutilserver.service.IWorkDayService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import org.springframework.web.client.RestTemplate;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @author: masterhai
// * @date: 2021/4/11:20:31
// * @description:
// */
//@Service
//@Slf4j
//public class WorkDayService implements IWorkDayService {
//    @Resource
//    private RestTemplate restTemplate;
//    @Resource
//    private WorkInfoDao workInfoDao;
//
//
//    @Override
//    public int insertWorkDayInfo2DB (String year) {
//        List<WorkDayInnerBean> workDayInfo = getWorkDayInfo(year);
//        //遍历集合,将非工作日的数据移除
//        if (workDayInfo == null || workDayInfo.size() < 1) {
//            return - 1;
//        }
//        //创建新集合保存数据
//        ArrayList<WorkDayInnerBean> newData = new ArrayList<>();
//        for (int i = workDayInfo.size() - 1; i >= 0; i--) {
//            WorkDayInnerBean bean = workDayInfo.get(i);
//            if (bean.getWorkday() == 1) {
//                //添加该对象到新集合
//                newData.add(bean);
//            }
//        }
//        //清空原集合
//        workDayInfo.clear();
//        return workInfoDao.insertWorkDayInfo(newData);
//    }
//
//    @Override
//    public List<WorkDayInnerBean> getWorkDayInfo (String year) {
//        //先拼接月份202101,202102,...,202111
//        StringBuffer sb = new StringBuffer();
//        for (int i = 1; i < 12; i++) {
//            //拼接年份
//            sb.append(year);
//            int len = String.valueOf(i).length();
//            //获取格式化后的月份
//            String month = ("0" + String.valueOf(i)).substring(len - 1, len + 1);
//            //拼接逗号
//            sb.append(month).append(",");
//        }
//        //拼接12月份
//        String months = sb.append(year).append("12").toString();
//        //发送请求获取数据
//        String url = "https://api.apihubs.cn/holiday/get?year=" + year + "&month=" + months + "&field=date,workday&size=400";
//        WorkResultBean workResultBean = restTemplate.getForObject(url, WorkResultBean.class);
//        return workResultBean.getData().getList();
//    }
//}
